package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;

    /**
     * 查询所有权限
     *
     * @return
     */
    @RequestMapping("findall")
    public Result findall() {
        try {
            List<Permission> permissionList = permissionService.findall();
            return new Result(true, "所有权限查询成功", permissionList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, "查询所有权限失败");
        }
    }

    @RequestMapping("findPermissionsByRoleId")
    public Result findPermissionsByRoleId(int id) {
        try {
            List<Integer> ids = permissionService.findPermissionsByRoleID(id);
            return new Result(true, "回显权限成功", ids);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, "回显权限失败");
        }
    }
}
